﻿package utils 
{
	import flash.events.ContextMenuEvent;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	import model.User;
	
	/**
	 * ...
	 * @author ...
	 */
	public class UserContextMenu {
		
		public static function getMenu(u:User):ContextMenu {
			var cm:ContextMenu = new ContextMenu();
			cm.hideBuiltInItems();
			var cmi:ContextMenuItem = new ContextMenuItem("© Vgallery", true);
			var cmi2:ContextMenuItem = new ContextMenuItem(u.name);
			var cmi3:ContextMenuItem = new ContextMenuItem("Отправить сообщение");
			cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onMenuSelect);
			cmi2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onMenuSelect);
			cmi3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onMenuSelect);
			cm.customItems = [cmi2, cmi3, cmi];
			function onMenuSelect(e:ContextMenuEvent):void 	{
				switch(e.target) {
					case cmi:
						navigateToURL(new URLRequest("http://vkontakte.ru/id4264707"))
					break;
					case cmi2:
						navigateToURL(new URLRequest("http://vkontakte.ru/id" + u.uid));
					break;
					case cmi3:
						navigateToURL(new URLRequest("http://vkontakte.ru/mail.php?act=write&to=" + u.uid))
					break;
				}
				
			}
			return cm
		}
		
	}
	
}